package com.dashan.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dashan.Constants;
import com.dashan.backend.datastore.DaoBase;
import com.dashan.backend.datastore.DsFriend;
import com.dashan.backend.datastore.DsFriendGroup;
import com.dashan.backend.datastore.DsFriendInvitation;
import com.dashan.backend.datastore.DsPosition;
import com.dashan.backend.datastore.DsSession;
import com.dashan.backend.datastore.DsStatus;
import com.dashan.backend.datastore.DsUser;
import com.dashan.backend.datastore.DsUserProfile;

@SuppressWarnings("serial")
public class VacuumDatabaseServlet extends DashanServlet {

    @Override
    public String getUrlPattern() {
        return "/vacuumdatabase";
    }
    
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        DaoBase dao = new DaoBase() {
        };
        dao.deleteAll(DsUser.class);
        dao.deleteAll(DsSession.class);
        dao.deleteAll(DsStatus.class);
        dao.deleteAll(DsPosition.class);
        dao.deleteAll(DsFriendInvitation.class);
        dao.deleteAll(DsFriend.class);
        dao.deleteAll(DsUserProfile.class);
        dao.deleteAll(DsFriendGroup.class);
        
        resp.getWriter().print(Constants.SUCCESS);
    }
}
